package com.wswy.wyjk.utils

import android.arch.lifecycle.MutableLiveData
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.my.httpapi.api.baseUtils.LogUtils
import timber.log.Timber

inline fun RecyclerView.Adapter<out RecyclerView.ViewHolder>.loadLayout(parent: ViewGroup, layoutId:Int) = LayoutInflater.from(parent.context).inflate(layoutId,parent,false)



inline fun View.visible() {
    this.visibility = View.VISIBLE
}

inline fun View.gone() {
    this.visibility = View.GONE
}

inline fun View.invisible() {
    this.visibility = View.INVISIBLE
}


inline fun <T> MutableLiveData<T>.reSend(){
    postValue(value)
}

inline fun SQLiteDatabase.execSQL(sql: String,showSQL: Boolean){
    if (showSQL){
        Timber.e("sql --> $sql")
        val st = System.currentTimeMillis()
        execSQL(sql)
        Timber.e("execSQL -->time ${System.currentTimeMillis() - st}")

    }else{
        execSQL(sql)
    }


}

inline fun SQLiteDatabase.rawQuery(sql:String, selectionArgs:Array<String>?, showSQL: Boolean): Cursor?{

    if (showSQL){
        Timber.e("sql --> $sql")
        Timber.e("args --> ${selectionArgs?.contentToString()}")
        val st = System.currentTimeMillis()

        val cursor = rawQuery(sql, selectionArgs)
        Timber.e("rawQuery -->time ${System.currentTimeMillis() - st}")
        LogUtils.e(sql)
        LogUtils.e(selectionArgs?.contentToString())
        return cursor
    }else{
        return rawQuery(sql, selectionArgs)
    }

}